package com.gg.data;

import com.gg.enums.ResultEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

@Data
@NoArgsConstructor//无参构造器
@AllArgsConstructor//全餐构造器
@Accessors(chain = true) //链式编程
//@RequiredArgsConstructor
public class Result<T> {
//    @NonNull
    private Integer code;
//    @NonNull
    private String message;
    private T data;

//    public Result setData(T data) {
//        this.data = data;
//        return this;
//    }

    public static Result response(ResultEnum resultEnum){
        Result result = new Result(resultEnum.getCode(), resultEnum.getMessage());
        return result;
    }

    public static Result OK(){
        Result result = new Result(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage());
        return result;
    }

    public static Result FAIL(){
        Result result = new Result(ResultEnum.ERROR.getCode(), ResultEnum.ERROR.getMessage());
        return result;
    }

    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

}
